﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace FourSquareWM
{
    public partial class formLogin : Form
    {
        RegistryKey settingsKey;

        internal string username;
        internal string password;

        public formLogin()
        {
            InitializeComponent();
        }
        
        private void formLogin_Load(object sender, EventArgs e)
        {
            settingsKey = Registry.CurrentUser.CreateSubKey("Software\\thebrent\\PocketNotepad");
            this.textBoxUsername.Text = (string)settingsKey.GetValue("Username");
            this.textBoxPassword.Text = (string)settingsKey.GetValue("Password");
            if (this.textBoxPassword.Text != "")
            {
                this.checkBoxSavePassword.Checked = true;
            }
        }

        private void menuItemOk_Click(object sender, EventArgs e)
        {
            settingsKey.SetValue("Username", this.textBoxUsername.Text, RegistryValueKind.String);
            if (this.checkBoxSavePassword.Checked == true)
            {
                settingsKey.SetValue("Password", this.textBoxPassword.Text, RegistryValueKind.String);
            }
            this.username = this.textBoxUsername.Text;
            this.password = this.textBoxPassword.Text;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void menuItemCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}